package com.shop.product.server.controller;

import com.shop.product.common.ProductInfoOutput;
import com.shop.product.common.ProductInfoVo;
import com.shop.product.server.service.ProductCategoryService;
import com.shop.product.server.service.ProductInfoService;
import com.shop.product.server.util.ResultUtil;
import com.shop.product.server.vo.ResultVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: dpengpeng
 * Date: 2018/5/18
 * Time: 22:38
 * Description:
 */
@RestController
@RequestMapping("product")
public class ProductController {

    private final ProductCategoryService productCategoryService;

    private final ProductInfoService productInfoService;

    @Autowired
    public ProductController(ProductCategoryService productCategoryService, ProductInfoService productInfoService) {
        this.productCategoryService = productCategoryService;
        this.productInfoService = productInfoService;
    }

    @GetMapping("list")
    public ResultVo list() {
        return ResultUtil.success(productCategoryService.list());
    }

    @PostMapping("listForOrder")
    public List<ProductInfoOutput> listForOrder(@RequestBody List<String> stringList) {
        return productInfoService.listForOrder(stringList);
    }

    @PostMapping("/buckleStock")
    public void buckleStock(@RequestBody List<ProductInfoVo> productInfoList) {
        productInfoService.buckleStock(productInfoList);
    }
}
